package com.situ.mall.thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable myCallable = new MyCallable();
        FutureTask<String> futureTask = new FutureTask<>(myCallable);
        Thread thread = new Thread(futureTask, "callable");
        thread.start();
        String str = futureTask.get();
        System.out.println(str);
    }

    public static void main4(String[] args) {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("ThreadDemo.run");
            }
        });
        thread.start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("ThreadDemo.run");
            }
        }).start();
    }

    public static void main3(String[] args) {
        MyRunnable myRunnable = new MyRunnable();
        Thread thread = new Thread(myRunnable, "runnable");
        thread.start();
        for (int i = 1; i <= 100; i++) {
            System.out.println(Thread.currentThread().getName() + " : " + i);;
        }
    }

    public static void main2(String[] args) {
        MyThread myThread = new MyThread();
        myThread.start();
        for (int i = 1; i <= 100; i++) {
            System.out.println(Thread.currentThread().getName() + " : " + i);;
        }
    }

    public static void main1(String[] args) {
        System.out.println("ThreadDemo.main");
        System.out.println(Thread.currentThread().getName());;
    }
}
